package com.android.customviewgroup;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.android.customviewgroup.viewholder.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    private List<TestBean> mList;
    private ViewGroupAdapter mViewGroupAdapter;
    private CustomViewGroup customViewGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mList = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            TestBean testBean = new TestBean();
            testBean.setName("name:" + i);
            mList.add(testBean);
        }
        mViewGroupAdapter = new ViewGroupAdapter<TestBean>(this, mList) {
            @Override
            public void convert(ViewHolder viewHolder, TestBean item, int position) {
                viewHolder.setText(R.id.xi_name, item.getName());
            }

            @Override
            public int getItemLayout() {
                return R.layout.custom_item;
            }
        };
        customViewGroup = findViewById(R.id.xi_custom_viewgroup);
        customViewGroup.setViewGroupAdapter(mViewGroupAdapter);
    }
}
